export const BASEURL = 'https://exshow-web.cbebaiwen.com/exhibitions';
//export const BASEURL = 'https://exshow-test.cbebaiwen.com/exhibitions';
//export const BASEURL = 'https://exshow-sever.cbebaiwen.com/exhibitions';
//export const BASEURL = 'https://3434iq8697.yicp.fun/exhibitions'
//export const BASEURL = 'https://2f07771y51.eicp.vip/exhibitions'


import {
	showLoading,
	hideLoading,
	toast
} from '@/utils/toast.js';


export const notoastpost = function(url, data, method = 'post') {
	// showLoading();
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASEURL + url,
			method,
			header: {
				//'content-type': 'application/x-www-form-urlencoded',
				'content-type': 'application/json',
				token: uni.getStorageSync('token')
			},
			data: {
				...data
			},
			success: res => {
				//console.log(res, 'http POST res')
				if (res.header.secretKey) {
					uni.setStorageSync('secretKey', res.header.secretKey);
				}

				if (res.data.code == 600 || res.data.code == '600') {
					toast('身份信息不正确，请登录');
					uni.removeStorageSync('userInfo_winxin');
					uni.removeStorageSync('token');
					setTimeout(function() {
						uni.redirectTo({
							url: '/pages/me/login'
						})
					}, 2000)
				} else if (res.statusCode == 200) {
					if (res.data.code == 200 || res.data.code == '200') {
						resolve(res.data);
					}
				} else {
					reject(res.data);
				}
			},
			fail: err => {
				reject(err);
			}
		})
	})
}


export const post = function(url, data, method = 'post') {
	// showLoading();
	return new Promise((resolve, reject) => {

		uni.request({
			url: BASEURL + url,
			method,
			header: {
				//'content-type': 'application/x-www-form-urlencoded',
				'content-type': 'application/json',
				token: uni.getStorageSync('token')
			},
			data: {
				...data
			},
			success: res => {
				//console.log(res, 'http POST res')
				if (res.header.secretKey) {
					uni.setStorageSync('secretKey', res.header.secretKey);
				}

				if (res.data.code == 600 || res.data.code == '600') {
					toast('身份信息不正确，请登录');
					uni.removeStorageSync('userInfo_winxin');
					uni.removeStorageSync('token');
					setTimeout(function() {
						uni.navigateTo({
							url: '/pages/me/login'
						})
					}, 2000)
				} else if (res.statusCode == 200) {
					if (res.data.code == 200 || res.data.code == '200') {
						resolve(res.data);
					} else {
						//toast(res.data.msg);
						// reject(res.data);
					}
				} else {
					//reject(res.data);
				}
			},
			fail: err => {
				reject(err);
			},
			complete() {
				// hideLoading();
			}
		})
	})
}




export const silencepost = function(url, data, method = 'post') {
	// showLoading();
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASEURL + url,
			method,
			header: {
				//'content-type': 'application/x-www-form-urlencoded',
				'content-type': 'application/json',
				token: uni.getStorageSync('token')
			},
			data: {
				...data
			},

			complete() {
				console.log('slilence post')
			}
		})
	})
}


export const get = function(url, data, method = 'GET') {
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASEURL + url,
			method,
			header: {
				'content-type': 'application/x-www-form-urlencoded',
				token: uni.getStorageSync('token')
			},
			data: {
				...data
			},
			success: res => {
				if (res.code == 600 || res.code == '600') {
					toast('身份信息不正确，请登录');
					uni.removeStorageSync('userInfo_winxin');
					uni.removeStorageSync('token');
					setTimeout(function() {
						uni.redirectTo({
							url: '/pages/me/login'
						})
					}, 2000)
				} else if (res.statusCode == 200) {
					resolve(res.data);
				} else {
					//reject(res.data);
				}
			},
			fail: err => {
				console.log(err, 'bbb');
				//reject(err);
			},
			complete() {
				// console.log('ccc');
				// hideLoading();
			}
		})
	})
}


export const iget = function(url, data, method = 'GET') {
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASEURL + url + data.param,
			method,
			header: {
				'content-type': 'application/x-www-form-urlencoded',
				token: uni.getStorageSync('token')
			},
			// data: {
			// 	...data
			// },
			success: res => {
				if (res.code == 600 || res.code == '600') {
					toast('身份信息不正确，请登录');
					uni.removeStorageSync('userInfo_winxin');
					uni.removeStorageSync('token');
					setTimeout(function() {
						uni.redirectTo({
							url: '/pages/me/login'
						})
					}, 2000)
				} else if (res.statusCode == 200) {
					resolve(res.data);
				} else {
					reject(res.data);
				}
			},
			fail: err => {
				console.log(err, 'bbb');
				reject(err);
			},
			complete() {
				// console.log('ccc');
				// hideLoading();
			}
		})
	})
}



export const noLogin = function(url, data, method = 'GET') {
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASEURL + url,
			method,
			header: {
				'content-type': 'application/x-www-form-urlencoded',
				token: uni.getStorageSync('token')
			},
			data: {
				...data
			},
			success: res => {
				if (res.code == 600 || res.code == '600') {
					toast('身份信息不正确，请登录');
					uni.removeStorageSync('userInfo_winxin');
					uni.removeStorageSync('token');
					setTimeout(function() {
						uni.navigateTo({
							url: '/pages/me/login'
						})
					}, 2000)
				} else if (res.statusCode == 200) {
					resolve(res.data);
				} else {
					reject(res.data);
				}
			},
			fail: err => {
				console.log(err, 'bbb');
				reject(err);
			},
			complete() {
				// console.log('ccc');
				// hideLoading();
			}
		})
	})
}


export const noLoginPost = function(url, data, method = 'post') {
	// showLoading();
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASEURL + url,
			method,
			header: {
				//'content-type': 'application/x-www-form-urlencoded',
				'content-type': 'application/json',
				token: uni.getStorageSync('token')
			},
			data: {
				...data
			},
			success: res => {
				if (res.data.code == 600 || res.data.code == '600') {
					toast('身份信息不正确，请登录');
					uni.removeStorageSync('userInfo_winxin');
					uni.removeStorageSync('token');
					setTimeout(function() {
						uni.navigateTo({
							url: '/pages/me/login'
						})
					}, 2000)
				} else if (res.statusCode == 200) {
					if (res.data.code == 200 || res.data.code == '200') {
						resolve(res.data);
					} else {
						reject(res.data);
					}
				} else {
					reject(res.data);
				}
			},
			fail: err => {
				reject(err);
			},
			complete() {
				// hideLoading();
			}
		})
	})
}



export const writeoffpost = function(url, data, method = 'post') {
	// showLoading();
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASEURL + url,
			method,
			header: {
				//'content-type': 'application/x-www-form-urlencoded',
				'content-type': 'application/json',
				token: uni.getStorageSync('token_writeoff')
			},
			data: {
				...data
			},
			success: res => {
				if (res.header.secretKey) {
					uni.setStorageSync('secretKey', res.header.secretKey);
				}

				if (res.data.code == 600 || res.data.code == '600') {
					toast('身份信息不正确，请登录');
					uni.removeStorageSync('userInfo_winxin');
					uni.removeStorageSync('token');
					setTimeout(function() {
						uni.redirectTo({
							url: '/pagesB/index/index'
						})
					}, 2000)
				} else if (res.statusCode == 200) {
					if (res.data.code == 200 || res.data.code == '200') {
						resolve(res.data);
					} else {
						reject(res.data);
					}
				} else {
					reject(res.data);
				}
			},
			fail: err => {
				reject(err);
			},
			complete() {
				// hideLoading();
			}
		})
	})
}